// store.js
import { makeAutoObservable, observable, action, reaction } from 'mobx'

class AppStore {
  count: number = 0

  constructor() {
    makeAutoObservable(this, {
      count: observable,
      increment: action,
      decrement: action,
    })
  }

  increment() {
    this.count++
  }

  decrement() {
    this.count--
  }

  onCountChange(callback) {
    return reaction(
      () => this.count,
      (newVal) => callback(newVal)
    )
  }
}

export const appStore = new AppStore()
